$(function () {


    $('.input_sub').on('click', function () {



        // 获取用户名和密码
        const username = $('.input_txt').val()
        const password = $('.input_pass').val()
        if (!username.trim() || !password.trim()) {
            $('.modal').modal('show')
            $('.modal-body p').text('请输入完整信息')
            $('.modal').modal({ keyboard: true })
            $('.btn-primary').on('click', function () {
                $('.modal').modal('hide')
            })
            return;
        };
        $.ajax({
            type: "post",
            url: bignews.user_login,
            data: {
                username,
                password
            },
            success(res) {
                if (res.code === 200) {
                    $('.modal-body p').text('登录成功')
                    $('.modal').modal('show')
                    $('.btn-primary').on('click', function () {
                        $('.modal').modal('hide')
                        localStorage.setItem('bignews_token', res.token)
                        location = "./index.html"
                    })
                } else {
                    $('.modal-body p').text('登录失败')
                    $('.modal').modal('show')
                    $('.btn-primary').on('click', function () {
                        $('.modal').modal('hide')
                    })
                }
            }
        });


    })

})